import { reactive } from 'vue'
import { UserService } from './common.object';

export const store = reactive({
	// user: null,
	user: {
		name: "test",
		ext: {},
	},
	role: 'visitor',

	activeNav: 'index',

	title: '',

	changeTitle(title) {
		this.title = title;
	},
	isVisitor() {
		return 'visitor' === this.role;
	},
	notVisitor() {
		return !this.isVisitor();
	},
	onLogin() {
		return new Promise((resolve, reject) => {
			UserService.info().then(data => {
				this.changeUser(data);

				resolve();
			})
		});
	},
	changeUser(user) {
		this.user = user;
		this.role = "user";
	},
	onLogout() {
		this.user = null;
		this.role = "visitor";
	},
});

